<?php
$user = blyn::app()->getCurrentUser();
$jq_openid = $user->getContextVariable('jq_openid');
$cs = Yii::app()->getClientScript();
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_find_1.css');
$cart = new BWCart();
$view = $cart->getView(array('itemData' => array('paymentStatus' => bcart::Payment_Status_Not_Paid)));
$view2 = $cart->getView(array('itemData' => array('paymentStatus' => bcart::Payment_Status_Waiting_Paid)));
foreach ($view2 as $cartList) {
    //reset status
    $cartList->addItem('paymentStatus', bcart::Payment_Status_Not_Paid);
}
$view = $view + $view2;
foreach ($view as $key=>$cartList) {
    $bookingTimeItem = $cartList->getItem('addToBookingCartTime');
    if($bookingTimeItem instanceof BTreeItem){
        $bookingTime = $bookingTimeItem->value;
        if(time()>$bookingTime+15*60){
            unset($view[$key]);
        }
    }
}
$totalCount = count($view);
?>

<meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, user-scalable=no">
<meta name="viewport" content="initial-scale=1.0,user-scalable=no,maximum-scale=1" media="(device-height: 568px)">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="full-screen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<header class="navbar">
                <div class="nav-wrap-left">
                    <!--<a class="react back" href="#"><i class="text-icon icon-back"></i></a>-->
                </div>
            <h1 class="nav-header">我的未支付订单</h1>

        <?php
        $screen = Blyn::app()->getUIManager()->getCurrentScreen();
        $wxControl = $screen->getChildControl('BUIWXControl_1');
        $wxControl->renderView('booking_navigation', array());
        ?>
        </header>
<style>
    .newInput{
        position: absolute;
width: 20px;
height: 20px;
margin-left: 20px;
    }
    .newDel{
        margin-left: 10px;
    }
    .payNow_2_style{
        background-color: #fdb338;
        color: #fff;
    }
</style>
<div id="tips"></div>
<div>
    <dl class="list" id="orders">
	<dd>
	<dl>
            <?php
            $quantity = 0;
            $totalMoney = 0;
            $serial = 0;
            $cartIdStr = '';
            foreach ($view as $cartList) {
                if ($cartList instanceof BTreeList) {
                    $serial++;
                    $cartId = $cartList->getId();
                    $price = $cartList->getItem('price')->value;
                    $unit = $cartList->getItem('moneyUnit')->value;
                    $quantity = $cartList->getItem('quantity')->value;
                    $productName = $cartList->getItem('productName')->value;
                    $productId = $cartList->getItem('productId')->value;
                    $bookingItem = new BWInputValue($productId);
                    $bookingList = new BTreeList($bookingItem);
                    if ($bookingList instanceof BTreeList){
                        $courtDisplayName = $bookingList->getItem('courtDisplayName')->value;
                        $date = date('Y.n.j', $bookingList->getItem('startTime')->value);
                        $startTime = date('G:i', $bookingList->getItem('startTime')->value);
                        $endTime = date('G:i', $bookingList->getItem('endTime')->value);
                        $court_price =  $bookingList->getItem('price')->value;
                        $region = $bookingList->getItem('region')->value;
                        $courtAddress = $bookingList->getItem('courtAddress')->value;
                        $str = $bookingList->getItem('courtName')->value;
                        $str = trim($str);
                        if (!empty($str)) {
                            $result = '';
                            for ($i = 0; $i < strlen($str); $i++) {
                                if (is_numeric($str[$i])) {
                                    $result.=$str[$i];
                                }
                            }
                        }
                        $bookdetail = new BWMessage($result);
                        $courtMedia = $bookdetail->getMediaManager()->getMedia('image');
                        $courtImage = " <h4>No Picture!</h4>";
                        if ($courtMedia instanceof BWMedia) {
                            $courtImage = $bookdetail->getMediaManager()->getMedia('image')->getContent();
                        }
                    }
                    $total = $price * $quantity;
                    if ($total != NULL)
                        $totalMoney += $total;
                }
                    //取出全部cartId
                    $cartIdStr = $cartId.'#'.$cartIdStr;
                    $BookingDetailUrl = $wxControl->getLinkUrl(array(
                        'name' => '订单详情',
                        'id' => 'showBookingDetail_1'),array(
                         'cartId' => $cartId, 
                         'bookingId' => $productId,'state'=>'unpaid',
                    ));
                ?>
            
		<dd class="dealcard dd-padding">
                    <div class="dealcard-block-right" style="margin-left: 0px;height: auto;">
<!--                                     <div class="left_picture" style="float: left;width: 1.7rem;height: 1.7rem;">
                                         <img src="<?php // echo Yii::app()->request->baseUrl.$courtImage;?>" width="100%" height="100%"/>
                                    </div>-->
                                <a href="<?php echo $BookingDetailUrl;?>">
                                    <div class="right_content" style="float: left;padding-left: .1rem;padding-top: .2rem;">
                                        <span style="color:black;"><?php echo $courtDisplayName; ?></span>
                                        <div>
                                            <span class="stars" style="margin-top:.2rem;">
                                                <i class="text-icon" style="font-family: inherit;font-weight: bold;"><span class="booking_date"><?php echo $date; ?></span>&nbsp;<?php echo $startTime; ?>-<?php echo $endTime; ?><?php // echo $regionAlias;?></i>
                                        </span>
                                        </div>
                                        <div class="price" style="margin-top:.2rem;">
                                            <strong style="color:#2BB2A3;font-size: .5rem;"><?php echo $court_price;?></strong>
                                            <span>元</span>
                                        </div>
                                    </div></a>
                                   
                                    <div class="right_btn" style="position:absolute;right: .1rem;top: .8rem;">
                                        <span class="line-right">
                                            <?php 
                                            echo $wxControl->getLink(array('name' => '删除', 'id' => 'deleteBookable_1'), array(
                                             'cartId'=>$cartId,
                                            'htmlOptions' => array(
                                                'enctype' => 'multipart/form-data',
                                                'class'=>'btn btn-weak color-strong newDel delete_btn',
                                                    )
                                            ));
                                            ?>
                                            <a href="<?php echo $BookingDetailUrl;?>" class="btn btn-weak color-strong newDel delete_btn payNow_2_style" style="color:#fff">查看</a>
                                        </span>
                                    </div>
                                    <div style="width: 100%;height: .01rem;clear: both;"></div>                   
		   </div>   
                </dd>
 <?php } ?>
                <?php
                if($totalCount){
                    $newCartIdStr = substr($cartIdStr,0,strlen($cartIdStr)-1);
                    $paidUrl = $wxControl->getLinkUrl(array('name' => 'pay_2','id' => 'payNow_2'), array(
					'cartIdStr'=>$newCartIdStr,
					'paidMoney' => $totalMoney,
					'paidCount' => $totalCount));
                    ?>
                <dd>
                    <div>
                       <form action="http://www.hualvhb.cn/pay/weixin/jsapicall.php" method="post">
			<input id="pUrl" type="hidden" name="pUrl" value="http://stage.billyn.net<?php echo $paidUrl;?>" />
                        <input id="totalCount" type="hidden" name="totalCount" value="<?php echo $totalCount;?>" />
			<input id="totalMoney" type="hidden" name="totalMoney" value="<?php echo $totalMoney;?>" />
			<input id="jq_openid" type="hidden" name="jq_openid" value="<?php echo $jq_openid;?>" />
                            <div class="wrapper buy-wrapper">
                              
                                    <input type="submit" name="submit" class="btn btn-strong btn-tip  buy-btn btn-block btn-larger" value="去结算"/>  
                            </div>
                        </form>
                    </div>
                </dd> 
                <?php
                }
                ?>
   
    </dl></dd>
    </dl>
	<?php if($quantity == 0) {?>           
        <dl style="margin-top: 0;">
            <dd style="margin: 0;">
                <?php $wxControl->renderView('none_list',array('message'=>'购物车空空如也，赶快去添加吧！'));?>
            </dd>
        </dl>
    <?php }?>
</div>
<footer>
<div class="footer-bar">
    <?php
//    $paidMoney = $totalMoney;
//    $paidCount = $totalCount;
//    $paidUrl = $wxControl->getLinkUrl(array('name' => 'pay','id' => 'payNow_1'), array('paidMoney' => $paidMoney,'paidCount' => $paidCount));
    ?>
    <!--<a class="btn btn-strong btn-tip J_buy buy-btn btn-block btn-larger" href="http://www.hualvhb.cn/pay/weixin/jsapicall.php?pUrl=http://stage.billyn.net<?php // echo $paidUrl;?>&pM=<?php // echo $paidMoney; ?>&pC=<?php // echo $paidCount; ?>">结算</a>-->
    <!--<a class="btn btn-strong btn-tip J_buy buy-btn btn-block btn-larger" href="#<?php // echo $paidUrl;?>">结算</a>-->

</div>
        <div class="footer-copyright">
            <div class="hr"></div>
            <span class="footer-copyright-text">
			Copyright © 2014 billyn.net </span>
        </div>
    </footer>